package com.study.collection.HashMap;

import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

/**
 * @ClassName HashMapErrorDemo
 * @Author: jianghaok
 * @Description // HashMap集合线程不安全案例展示
 * @Date: 2022/5/10
 * @Version 1.0
 */
// HashMap集合线程不安全案例展示
public class HashMapErrorDemo {

    public static void main(String[] args) {
        //演示HashMap
        Map<String,String> map = new HashMap<>();

        for (int i = 0; i <30; i++) {
            String key = String.valueOf(i);
            new Thread(()->{
                //向集合添加内容
                map.put(key,UUID.randomUUID().toString().substring(0,8));
                //从集合获取内容
                System.out.println(map);
            },String.valueOf(i)).start();
        }
    }
}
